package com.ruoyi.web.controller.bussiness;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.bo.AssessmentBo;
import com.ruoyi.system.domain.vo.AssessmentVo;
import com.ruoyi.system.service.IAssessmentService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import java.util.Arrays;
import java.util.List;

/**
 * 勤务考核
 *
 * @author ruoyi
 * @date 2025-06-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/assessment")
public class AssessmentController extends BaseController {

    private final IAssessmentService iAssessmentService;

    /**
     * 查询勤务考核列表
     */
    @SaCheckPermission("system:assessment:list")
    @GetMapping("/list")
    public TableDataInfo<AssessmentVo> list(AssessmentBo bo, PageQuery pageQuery) {
        return iAssessmentService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出勤务考核列表
     */
    @SaCheckPermission("system:assessment:export")
    @Log(title = "勤务考核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AssessmentBo bo, HttpServletResponse response) {
        List<AssessmentVo> list = iAssessmentService.queryList(bo);
        ExcelUtil.exportExcel(list, "勤务考核", AssessmentVo.class, response);
    }

    /**
     * 获取勤务考核详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:assessment:query")
    @GetMapping("/{id}")
    public R<AssessmentVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iAssessmentService.queryById(id));
    }

    /**
     * 新增勤务考核
     */
    @SaCheckPermission("system:assessment:add")
    @Log(title = "勤务考核", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody AssessmentBo bo) {
        return toAjax(iAssessmentService.insertByBo(bo));
    }

    /**
     * 修改勤务考核
     */
    @SaCheckPermission("system:assessment:edit")
    @Log(title = "勤务考核", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AssessmentBo bo) {
        return toAjax(iAssessmentService.updateByBo(bo));
    }

    /**
     * 删除勤务考核
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:assessment:remove")
    @Log(title = "勤务考核", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iAssessmentService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
